<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
    String xm = this.getServletContext().getInitParameter("path");
	String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"+xm;
%>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加房间</title>
<base target="_self" />

<link href="<%=path1%>/ht/Styles/css.css" rel="stylesheet" type="text/css" />
<link href="<%=path1%>/ht/Styles/ts_css.css" rel="stylesheet" type="text/css" />
<script src="<%=path1%>/ht/Scripts/My97DatePicker/WdatePicker.js"
	type="text/javascript"></script>
<script src="<%=path1%>/ht/Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="<%=path1%>/ht/Scripts/IndexManager.js" type="text/javascript"></script>
<!-- <script src="Scripts/jquery.min.js" type="text/javascript" ></script>
<script src="Scripts/jquery.validate.min.js" type="text/javascript" ></script> -->

<script type="text/javascript">
	//添加房间信息
	function addAjax() {
		//alert("走了么");
		$.ajax({
			data : {

				room_code : $("#room_code").val(),
				build_up_area : $("#build_up_area").val(),
				inner_area : $("#inner_area").val(),
				apartment_layout_id : $("#apartment_layout_id").val(),
/* 			    inner_price : $("#inner_price").val(),
				unit_price : $("#unit_price").val(), */
			    floor : $("#floor").val(),
			    state : $("#state").val(),
				unit_id : $("#unit_id").val(),
				purpose_id : $("#purpose_id").val(),
				build_id : $("#build_id").val(),
				opening_report_id : $("#opening_report_id").val(),
				project_id : $("#project_id").val(),
				standard_price:$("#standard_price").val(),
				inners:$("#inners").val(),
				units:$("#units").val()
			},
				type : "POST",
				datatype : 'json',
				url : "<%=path1%>/qt/ht/room/addRoom.do",
				error : function(data) {
				   alert("出错了");
			},
				success : function(data) {
					window.location.href = "<%=path1%>/qt/ht/room/selectAll.do";
				}
		});
	}

<%-- 	//遍历项目的名字
	$.ajax({
			url : "<%=path1%>/qt/ht/project/selectAlls.do",
			datatype : 'json',
			error : function(data) {
		     	alert("项目出错了！！");
			},
			success : function(data) {
				//alert("项目成功了");	    	   
			   var len = data.msg.length;
				 //alert(project_id);
			   var html = "";
				if (len > 0) {
					data.msg.forEach(function(e) {
						if (e.project_id == project_id) {
							//alert(e.project_name);
							html += "<option value="+e.project_id+" selected='selected'>"
									+ e.project_name + "</option>";
								} else {
									html += "<option value="+e.project_id+">"
										+ e.project_name + "</option>";
							}
					})
				//alert(html);
			$("#project_id").append(html);
			}
		}
});

	//遍历楼栋的名字
	$.ajax({
				url : "<%=path1%>/qt/ht/build/selectAlls.do",
				datatype : 'json',
				error : function(data) {
					alert("楼栋出错了！！");
				},
				success : function(data) {
					//alert("楼栋成功了");	    	   
					var len = data.msg.length;
					//alert(build_id);
					var html = "";
					if (len > 0) {
						data.msg.forEach(function(e) {
									if (e.build_id == build_id) {
										//alert(e.build_name);
										html += "<option value="+e.build_id+" selected='selected'>"
												+ e.build_name + "</option>";
									} else {
										html += "<option value="+e.build_id+">"
												+ e.build_name + "</option>";
									}
								})
						//alert(html);
						$("#build_id").append(html);
					}
				}
			});

	//遍历单元表的表名
	$.ajax({
				url : "<%=path1%>/qt/ht/unit/selectAlls.do",
				datatype : 'json',
				error : function(data) {
					alert("单元出错了！！");
				},
				success : function(data) {
					//alert("单元成功了");	    	   
					var len = data.msg.length;
					//alert(unit_id);
					var html = "";
					if (len > 0) {
						data.msg
								.forEach(function(e) {
									if (e.unit_id == unit_id) {
										//alert(e.project_name);
										html += "<option value="+e.unit_id+" selected='selected'>"
												+ e.unit_code + "</option>";
									} else {
										html += "<option value="+e.unit_id+">"
												+ e.unit_code + "</option>";
									}
								})
						//alert(html);
						$("#unit_id").append(html);
					}
				}
			});
 --%>
	//遍历户型名字
	$.ajax({
				url : "<%=path1%>/ht/apar/selectAlls.do",
				datatype : 'json',
				error : function(data) {
					alert("户型出错了！！");
				},
				success : function(data) {
					//alert("户型成功了");	    	   
					var len = data.msg.length;
					//alert(apartment_layout_id);
					var html = "";
					if (len > 0) {
						data.msg.forEach(function(e) {
									if (e.apartment_layout_id == apartment_layout_id) {
										//alert(e.apartment_layout);
										html += "<option value="+e.apartment_layout_id+" selected='selected'>"
												+ e.apartment_layout
												+ "</option>";
									} else {
										html += "<option value="+e.apartment_layout_id+">"
												+ e.apartment_layout
												+ "</option>";
									}
								})
						//alert(html);
						$("#apartment_layout_id").append(html);
					}
				}
			});

	//遍历用途的名字
	$.ajax({
				url : "<%=path1%>/ht/purpose/selectAlls.do",
				datatype : 'json',
				error : function(data) {
					alert("12333出错了！！");
				},
				success : function(data) {    	   
					var len = data.msg.length;
					var html = "";
					if (len > 0) {
						data.msg
								.forEach(function(e) {
									if (e.purpose_id == purpose_id) {
										//alert(e.purpose);
										html += "<option value="+e.purpose_id+" selected='selected'>"
												+ e.purpose + "</option>";
									} else {
										html += "<option value="+e.purpose_id+">"
												+ e.purpose + "</option>";
									}
								})
						//alert(html);
						$("#purpose_id").append(html);
					}
				}
			});
</script>
  <script type="text/javascript">
  function breaks(){
	  window.location.href="<%=path1%>/qt/ht/room/selectAll.do";
  }
  </script>
<script type="text/javascript">
	function room_codes() {

		var room_code = document.getElementById("room_code").value;

		if (room_code == "" || room_code == null) {
			//alert("房间房号不能为空");
			//room_code.focus();
			return false;
		}
		return true;
	}

	function build_up_areas() {
		var build_up_area = $("#build_up_area").val();
		if (build_up_area == "" || build_up_area == null) {
			//alert("实际面积不能为空");
			//$("#build_up_area").focus();
			return false;
		}
		return true;
	}

	function apartment_layout_ids() {
		var apartment_layout_id = $("#apartment_layout_id").val();
		if (apartment_layout_id == "" || apartment_layout_id == null) {
			//alert("户型编号不能为空");
			//$("#apartment_layout_id").focus();
			return false;
		}
		return true;
	}

	function unit_ids() {
		var unit_id = $("#unit_id").val();
		if (unit_id == "" || unit_id == null) {
			//alert("单元编号不能为空");
			//$("#unit_id").focus();
			return false;
		}
		return true;
	}

	function build_ids() {
		var build_id = $("#build_id").val();
		if (build_id == "" || build_id == null) {
			//alert("楼栋编号不能为空");
			//$("#build_id").focus();
			return false;
		}
		return true;
	}

	
	function innerss() {
		var inners = $("#inners").val();
		if (inners == "" || inners == null) {
			//alert("套内面积不能为空");
			//$("#inners").focus();
			return false;
		}
		return true;
	}
	
	function unitss() {
		var units = $("#units").val();
		if (units == "" || units == null) {
			//alert("建筑面积不能为空");
			//$("#units").focus();
			return false;
		}
		return true;
	}

	function project_ids() {
		var project_id = $("#project_id").val();
		if (project_id == "" || project_id == null) {
			//alert("项目编号不能为空");
			//$("#project_id").focus();
			return false;
		}
		return true;
	}
</script>
   <script type="text/javascript">
       function danji(){
    	   if(project_ids()==true & unitss()==true & innerss()==true & build_ids()==true & unit_ids()==true & 
            apartment_layout_ids()==true & build_up_areas()==true & room_codes()){
    		   addAjax();
    	   }else{
    		   alert("红色星号为必填项！");
    	   }
       }
   </script>
</head>
<body>

	<form id="form1" method="post" name="form1">
		<div id="divTwo">
			<table width="100%" border="0" cellpadding="3" cellspacing="3"
				class="table_list1">
				<h2 align="center">添加房间信息</h2>

				<tr>
					<td width="35%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 项目名称:
					</td>
					<td width="10%" class="table_list1_style2"><select type="text"
						id="project_id" onblur="project_ids()" style="width: 140px">
						<c:forEach items="${proj}" var="a">
					     <option value="${a.project_id}">${a.project_name}</option>
					   </c:forEach> 
					</select></td>
					<td width="10%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 楼栋名称:
					</td>
					<td width="45%" class="table_list1_style2"><select type="text"
						id="build_id" onblur="build_ids()" style="width: 140px">
						<c:forEach items="${bu}" var="a">
					     <option value="${a.build_id}">${a.build_name}</option>
					   </c:forEach> 
					</select></td>
				</tr>

				<tr>
					<td width="35%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 单元名称:
					</td>
					<td width="10%" class="table_list1_style2"><select type="text"
						id="unit_id" onblur="unit_ids()" style="width: 140px">
						<c:forEach items="${un}" var="a">
					     <option value="${a.unit_id}">${a.unit_code}</option>
					   </c:forEach> 
					</select></td>
					<td width="10%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 户型名称:
					</td>
					<td width="45%" class="table_list1_style2"><select type="text"
						id="apartment_layout_id" onblur="apartment_layout_ids()"
						style="width: 140px">
					</select></td>
				</tr>
				<tr>
					<td width="35%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 用途名称:
					</td>
					<td width="10%" class="table_list1_style2"><select type="text"
						id="purpose_id" onblur="purposes_ids()" style="width: 140px">
					</select></td>
					<td width="10%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 房间房号:
					</td>
					<td width="45%" class="table_list1_style2"><input type="text"
						id="room_code" onblur="room_codes()" /></td>
				</tr>

				<tr>
					
					<td width="35%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 实际面积:
					</td>
					<td width="10%" class="table_list1_style2"><input type="text"
						id="build_up_area" onblur="build_up_areas();" /></td>
						<td width="10%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 套内面积:
					</td>
					<td width="45%" class="table_list1_style2"><input type="text"
						id="inners" onblur="innerss();" /></td>
				</tr>

				<tr>
					<td width="35%" class="table_list1_style1">
						<p></p> <span style="color: Red">*</span> 建筑面积:
					</td>
					<td width="10%" class="table_list1_style2"><input type="text"
						id="units" onblur="unitss();" /></td>
						<td width="10%" class="table_list1_style1">
						<td width="40%" class="table_list1_style2">
				</tr>

				<tr align="center">
					<td class="table_list1_style2"></td>
					<td class="table_list1_style2" style="margin-left: 10px"><input
						align="center" type="button" id="send" value="添加" tabindex="1"
						class="button" onclick="danji();" /></td>
					<td class="table_list1_style2" align="center"><input
						type="button" class="button" value="返回" tabindex="1"
						onclick="breaks();" /></td>
					<td class="table_list1_style2" align="center"></td>
				</tr>
			</table>
		</div>
	</form>
</body>
</html>